/**
 * Created by Administrator on 2017/11/29.
 */
import {insertSystemConfig,querySystemConfig,updateSystemConfig} from '../services/adminManageApi';
export default{
    namespace:'systemConfigEdit',
    state:{
        submitting:false,
        loading:false,
        data:{
            list:[],
            pagination:{},
        },
    },
    effects:{
        *insertSystemConfig({payload,callback},{put,call}){
            yield put({
                type:'changeSubmitting',
                payload:true
            });
            const response=yield call(insertSystemConfig,payload);
            yield put({
                type:'handleResponse',
                payload:response,
            });
            yield put({
                type:'changeSubmitting',
                payload:false,
            })
            if(callback)callback(response);
        },
        *updateSystemConfig({payload,callback},{put,call}){
            yield put({
                type:'changeSubmitting',
                payload:true
            });
            const response=yield call(updateSystemConfig,payload);
            yield put({
                type:'handleResponse',
                payload:response,
            });
            yield put({
                type:'changeSubmitting',
                payload:false,
            })
            if(callback)callback(response);
        }
    },
    reducers:{
        changeSubmitting(state,{payload}){
            return({
                ...state,
                submitting:payload,
            })
        },
        handleResponse(state,{payload}){
            return ({
                ...state,
                result:payload.result,
            })
        },
        handleUpdate(state,{payload}){
            return ({
                ...state,
            })
        },
        changeLoading(state,{payload}){
            return ({
                ...state,
                loading:payload,
            })
        },
        handleQueryParam(state,{payload}){
            return ({
                ...state,
                data:payload.resultData.systemParam,
            })
        }
    },
};